<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>离职流程</title>
    <script src="../../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../../res/js/Tools.js" charset="utf-8"></script>
    <script src="../../../../../res/js/error.js" charset="utf-8"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../../res/images/favicon.ico">
    <link rel="stylesheet" href="../../../../../res/layui/css/layui.css" media="all">
</head>
<body style="padding: 10px">
<h1 align="center" style="margin-bottom: 20px">员工辞职申请</h1>
<form class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <input type="hidden" id="pkDimissionId" name="pkDimissionId"/>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">姓名</label>
            <div class="layui-input-inline">
                <!--<select name="personnelId" id="personnelId" lay-filter="aihao" lay-search="">
                    <option value="" selected="">请选择</option>
                </select>-->
                <input autocomplete="off" class="layui-input" disabled name="personnelName"
                       id="personnelName"
                       type="text"/>
                <input id="personnelId" type="hidden" name="personnelId"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">身份证号</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" id="personnelIdentity"
                       name="personnelIdentity" placeholder="请输入身份证号" disabled
                       type="text"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">所在部门</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" disabled name="departmentName"
                       id="departmentName"
                       type="text"/>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">入职时间</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" disabled id="entryTime" name="entryTime"
                       placeholder="yyyy-MM-dd"
                       type="text">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">申请日期</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" disabled id="dimissionCurrentDate"
                       name="dimissionCurrentDate"
                       placeholder="yyyy-MM-dd HH:mm:ss"
                       type="text">
            </div>
        </div>


    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">计划正式离职日期</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" id="dimissionTime" lay-verify="date" name="dimissionTime"
                       placeholder="yyyy-MM-dd（必填）"
                       type="text">
            </div>
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">离职类型</label>
        <div class="layui-input-block" id="dimissionType">
            <input type="radio" name="dimissionType" value="0" title="试用期内离职">
            <input type="radio" name="dimissionType" value="1" title="合同期内离职" checked="">
            <input type="radio" name="dimissionType" value="2" title="合同到期">
            <input type="radio" name="dimissionType" value="3" title="其他">
        </div>
    </div>

    <div class="layui-form-item" pane="">
        <label class="layui-form-label">离职原因类型</label>
        <div class="layui-input-block" id="dimissionCauseType">
            <input type="radio" name="dimissionCauseType" value="0" title="主动离职" checked="">
            <input type="radio" name="dimissionCauseType" value="1" title="辞退">
            <input type="radio" name="dimissionCauseType" value="2" title="其他">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">离职原因</label>
        <div class="layui-input-block">
            <input type="text" id="dimissionCause" name="dimissionCause" autocomplete="off" placeholder="请输入离职原因"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">对公司希望</label>
        <div class="layui-input-block">
            <input type="text" name="companyExpectation" id="companyExpectation" autocomplete="off" placeholder="对公司希望"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 175px">离职后部门安排交接给</label>
        <div class="layui-input-block" style="margin-left:175px">
            <select name="personnelIds" id="personnelIds" lay-verify="required" lay-search="">
                <option value="" selected="">请选择员工（必填）</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">员工离职须知</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" disabled="">
                1、试用期员工需提前3天提出申请，正式员工需要提前30天提出申请，以便部门做好充分的工作交接；
                2、提出申请期间不得传播任何负面信息，否则公司按照劳动纪律管理规定处理；
                3、离职审批后请做好离职交接工作。
            </textarea>
            <input type="checkbox" name="consent" id="consent" lay-skin="primary" title="同意上述员工离职须知">
        </div>
    </div>
    <hr/>
    <!--<div class="layui-form-item layui-form-text">
        <label class="layui-form-label">主管部门审核意见</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" id="leadershipContent" name="leadershipContent" class="layui-textarea">
            </textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">行政人事部审核意见</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" id="personnelCondition" name="personnelCondition" class="layui-textarea">
            </textarea>
        </div>
    </div>-->
    <div class="layui-form-item">
        <div class="layui-input-block" id="flows">
            <button type="submit" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1">立即提交</button>
            <input type="button" id="demo3" class="layui-btn layui-btn-primary" value="取消">
        </div>
    </div>
</form>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>流程日志</legend>
</fieldset>
<ul class="layui-timeline" id="schedule">

</ul>
<script>
    var table2;
    // 修改赋值
    let pkDimissionId = getQueryString("pkDimissionId");
    layui.use(['form', 'table', 'layedit', 'laydate'], function () {
        var table = layui.table
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , form = layui.form;
        // 入职日期
        laydate.render({
            elem: '#entryTime'
        });
        // 离职申请日期
        laydate.render({
            elem: '#dimissionCurrentDate'
        });
        // 正式离职日期
        laydate.render({
            elem: '#dimissionTime'
        });

        let isRes = getAjaxById(getRootPath() + "OaDimissionFlowAction/getDimissionFlow");
        if (isRes) {
            /*layer.alert('你已提交申请，请勿重复提交', {
                icon: 2,closeBtn: 0
            }, function(){
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });*/
            //墨绿深蓝风
            layer.alert('你已提交辞职申请请勿重复提交', {
                skin: 'layui-layer-molv' //样式类名
                ,closeBtn: 0
            }, function(){
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });

        }


        let res;
        let personnelIds;
        if (pkDimissionId) {
            res = getAjaxById(getRootPath() + "OaDimissionFlowAction/findById/" + pkDimissionId);

            $("input[name=dimissionType][value='0']").attr("checked", res.dimissionType == 0 ? true : false); // 离职类型 试用期内离职
            $("input[name=dimissionType][value='1']").attr("checked", res.dimissionType == 1 ? true : false); // 离职类型 合同期内离职
            $("input[name=dimissionType][value='2']").attr("checked", res.dimissionType == 2 ? true : false); // 离职类型 合同到期
            $("input[name=dimissionType][value='3']").attr("checked", res.dimissionType == 3 ? true : false); // 离职类型 其他

            $("input[name=dimissionCauseType][value='0']").attr("checked", res.dimissionCauseType == 0 ? true : false); // 离职原因类型 主动离职
            $("input[name=dimissionCauseType][value='1']").attr("checked", res.dimissionCauseType == 1 ? true : false); // 离职原因类型 辞退
            $("input[name=dimissionCauseType][value='2']").attr("checked", res.dimissionCauseType == 2 ? true : false); // 离职原因类型 其他

            $("#dimissionCause").val(res.dimissionCause); // 离职原因
            $("#companyExpectation").val(res.dimissionCause); // 对公司希望
            $("#dimissionCurrentDate").val(dateFormat('yyyy-MM-dd', new Date(res.dimissionCurrentDate))); // 申请日期
            $("#dimissionTime").val(dateFormat('yyyy-MM-dd', new Date(res.dimissionTime)));//正式离职日期
            personnelIds = res.personnelIds;

            res = getAjaxById(getRootPath() + "OaPersonnelAction/findById/" + res.personnelId);
            // 离职人员id
            $("#personnelId").val(res.data.pkPersonnelId);
            //离职人员名称
            $("#personnelName").val(res.data.personnelName);
            // 离职人员部门
            $("#departmentName").val(res.data.departmentName);
            // 离职人员身份证
            $("#personnelIdentity").val(res.data.personnelIdentity);
            // 入职日期
            $("#entryTime").val(dateFormat('yyyy-MM-dd', new Date(res.data.entryTime)));
        } else {
            res = getAjaxById(getRootPath() + "OaPersonnelAction/getUser");
            // 离职人员id
            $("#personnelId").val(res.pkPersonnelId);
            //离职人员名称
            $("#personnelName").val(res.personnelName);
            // 离职人员岗位
            $("#departmentName").val(res.departmentName);
            // 离职人员身份证
            $("#personnelIdentity").val(res.personnelIdentity);
            if(res.entryTime){
                // 填表日期
                $("#entryTime").val(dateFormat('yyyy-MM-dd', new Date(res.entryTime)));
            }
            //正式离职日期
            $("#dimissionCurrentDate").val(dateFormat('yyyy-MM-dd', new Date()));
        }


        //查询同一个部门下所有人员
        if (res.pkDepartmentId) {
            res = getAjaxById(getRootPath() + "OaPersonnelAction/selectByDepartmentId/" + res.pkDepartmentId);
        } else {
            res = getAjaxById(getRootPath() + "OaPersonnelAction/selectByDepartmentId/0");
        }

        //赋值人员下拉框
        $("#personnelIds").html('<option value="" selected="">请选择员工（必填）</option>');
        $.each(res.data, function (index, item) {
            $("#personnelIds").append('<option value="' + item.pkPersonnelId + '">' + item.personnelName + '</option>')
        });
        $("#personnelIds").val(personnelIds);


        form.render();


        /*if (pkDimissionId){
                   $("#flows").hide();
               }else{
                   $("#flowTwo").hide();
        }*/

        //监听提交
        form.on('submit(demo1)', function (data) {

            /*layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            });*/
            if (!$("#consent").prop("checked")) {
                layer.alert("请同意员工离职须知", {
                    title: '提示'
                });
                return false;
            }

            let datas = {
                personnelId: $("#personnelId").val(), // 申请人id
                entryTime: $("#entryTime").val(), // 入职日期
                dimissionTime: $("#dimissionTime").val(), // 正式离职日期
                dimissionCurrentDate: $("#dimissionCurrentDate").val(), // 离职日期
                personnelIds: $("#personnelIds").val(), // 交接人员
                dimissionCause: $("#dimissionCause").val(), // 离职原因
                companyExpectation: $("#companyExpectation").val(), // 对公司希望
                dimissionType:$('#dimissionType input[name="dimissionType"]:checked ').val(),
                dimissionCauseType:$('#dimissionCauseType input[name="dimissionCauseType"]:checked ').val(),
                pkDimissionId: pkDimissionId
            };
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            let res = postAjax(getRootPath() + "OaDimissionFlowAction/addDimissionFlow", datas);
            //console.info("调用请求");
            if (res === 1) {
                layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                setTimeout(function () {
                    formClose();
                }, 3000);
                setTimeout(function () {
                    parent.layui.table.reload('test');//刷新父页面
                    //window.parent.location.reload();//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 3001);
                //window.location.reload();//刷新页面
            } else if (res === 500) {

            } else {
                layer.msg("新增失败");
            }
            return false;
        });

        $("#demo3").on("click", function () {
            //询问框
            layer.confirm('是否关闭该页面？', {
                btn: ['是的', '取消'] //按钮
            }, function () {
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                //window.parent.location.reload();//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });
        });

        if (pkDimissionId) {
            const ress = getAjaxById(getRootPath() + "OaFlowAction/selectFlowSchedule/" + pkDimissionId);
            $("#schedule").html("");
            $.each(ress, function (index, item) {
                if (item.createdBy) {
                    $("#schedule").append('<li class="layui-timeline-item">\n' +
                        '        <i class="layui-icon layui-timeline-axis"></i>\n' +
                        '        <div class="layui-timeline-content layui-text">\n' +
                        '            <h3 class="layui-timeline-title">' + dateFormat('yyyy-MM-dd hh:mm:ss', new Date(item.createdTime)) + '&nbsp;&nbsp;&nbsp;' + item.flowName + '</h3>\n' +
                        '            <p>' + item.formReason + '</p>\n' +
                        '            <p>操作人：' + item.createdBy + '</p>\n' +
                        '        </div>\n' +
                        '    </li>')

                } else {
                    $("#schedule").append('<li class="layui-timeline-item">\n' +
                        '        <i class="layui-icon layui-timeline-axis"></i>\n' +
                        '        <div class="layui-timeline-content layui-text">\n' +
                        '            <h3 class="layui-timeline-title">' + dateFormat('yyyy-MM-dd hh:mm:ss', new Date(item.createdTime)) + '&nbsp;&nbsp;&nbsp;' + item.flowName + '</h3>\n' +
                        '            <p>' + item.formReason + '</p>\n' +
                        '        </div>\n' +
                        '    </li>')
                }
            });
        }


    });
</script>
</body>
</html>